<?php

namespace app\api\controller\v3;

use api\channel\jutuike\EleUnion;
use think\Request;

class Takeout extends \app\api\controller\v2\Takeout
{
    public function ele(Request $request)
    {
        $res[] = [
            'sub_type' => 1,
            'act_id' => 4,
            'title' => '每日领红包',
            'click_url' => '',
            'intro' => '介绍',
        ];
//        $res[] = [
//            'sub_type' => 3,
//            'act_id' => 5,
//            'title' => '果蔬生鲜',
//            'click_url' => '',
//            'intro' => '介绍',
//        ];

        $extend = new EleUnion();

        $params['agent_id'] = $this->request->agentChannel['agent_id'];
        $params['user_id'] = $this->request->user['id'];
        $params['channel_id'] = $this->request->agentChannel['id'];

        foreach ($res as &$value) {
            $info = $extend->productUrl($params,$value['act_id']);
            $value['click_url'] = $info['h5']??'';
            $value = array_merge($value,$info);
        }

        return success('',$res);
    }

    /**
     * 美团券包推广链接
     * @return \think\response\Json
     * @throws \think\Exception
     */
    public function generateUrl() {
        if ($msg = dmjValidate([
            'act_id' => 'require',
        ], [], input())) {
            return fail($msg);
        }

        $params = [];
        $params['act_id'] = input('act_id');
        $params['agent_id'] = $this->request->agentChannel['agent_id'];
        $params['user_id'] = $this->request->user['id'];
        $params['channel_id'] = $this->request->agentChannel['id'];
        $meituan = new \app\common\service\Meituan($params['agent_id']);
        $res = $meituan->generateLink($params);
        return success('', $res);
    }

}